package luanvan.app.foodnote.library;

import java.util.ArrayList;
import java.util.List;


import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import org.json.JSONObject;

import android.util.Log;

public class UserFunctions {

	private JSONParser jsonParser;
	
	private static String loginURL = "http://demoluanvan.iblogger.org/register_login_user.php";
	private static String registerURL = "http://demoluanvan.iblogger.org/register_login_user.php";
	
	/*private static String loginURL = "http://172.16.65.120/foodnoteserver/register_login_user.php";
	private static String registerURL = "http://172.16.65.120/foodnoteserver/register_login_user.php";*/
	
	private static String login_tag = "login";
	private static String register_tag = "register";
	
	public UserFunctions(){
		jsonParser = new JSONParser();
	}
	
	public JSONObject loginUser(String email, String password){
		List<NameValuePair> params = new ArrayList<NameValuePair>();
		params.add(new BasicNameValuePair("tag", login_tag));
		params.add(new BasicNameValuePair("email", email));
		params.add(new BasicNameValuePair("password", password));
		
		JSONObject json = jsonParser.makeHttpRequest(loginURL, "POST", params);
		Log.e("JSON", json.toString());
		return json;
	}
	
	public JSONObject registerUser(String name, String email, String password){
		List<NameValuePair> params = new ArrayList<NameValuePair>();
		params.add(new BasicNameValuePair("tag", register_tag));
		params.add(new BasicNameValuePair("name", name));
		params.add(new BasicNameValuePair("email", email));
		params.add(new BasicNameValuePair("password", password));
		
		JSONObject json = jsonParser.makeHttpRequest(registerURL, "POST", params);
		
		return json;
	}
	
}
